function wxpay(app, that, orderId, redirectUrl, payType, money, toType) {
  let token = wx.getStorageSync('token')
  wx.request({
    url: app.apiUrl('/pay/wxpay/pay'),
    header: {
      "Authorization": 'Bearer ' + token
    },
    data: {
      id: orderId,
      type: payType,
      money: money
    },
    method:'GET',
    success: function(res){
      //res.data.code = 0
      console.log(res.data)
      if(res.data.data){
        // 发起支付
        wx.requestPayment({
          timeStamp: res.data.data.timeStamp,
          nonceStr: res.data.data.nonceStr,
          package: res.data.data.package,
          // package: 'prepay_id=' + res.data.data.prepay_id,
          // signType:'MD5',
          signType: res.data.data.signType,
          paySign: res.data.data.paySign,
          fail:function (e) {
            wx.showToast({title: '支付失败'})
            if (toType == 0) {
              that.data.toOrderList = false
              wx.redirectTo({
                url: "/pages/order-list/index?type=1"
              })
            }
            

          },
          success:function () {
            wx.showToast({title: '支付成功'})
            if (toType == 0) {
              that.data.toOrderList = false
              wx.redirectTo({
                url: redirectUrl
              })
            }
            
          }
        })
      } else {
        wx.showToast({ title: '服务器忙' + res.data.code + res.data.msg})
      }
    }
  })
}

module.exports = {
  wxpay: wxpay
}
